package functions 
{	import functions.FunctionNode;	/**	 * @author admin	 */	public class GetfFunctionNode extends FunctionNode 
	{
		public function GetfFunctionNode()
		{
			funcname = "getf";	
			functiontype = FUNCTION;
		}
		
		override public function getValue( args : XML, scope : Object ) : XML
		{
			var returnXML = <list/>;
			// this does an interesting thing.
			// it cycles through the list that's passed as the first arg,
			// and returns the elements AFTER the element whose value matches the second arg.
			// ex: (getf '(:x 12 :y 15) :x)
			// will return 12.
			// 
			
			var gottenlist:XML = args.children()[0];
			var labelname:XML = args.children()[1];
			trace("GETF.getValue()");
			var positionNumber : int = getPositionInList( gottenlist, labelname );
			trace("gottenlist = " + gottenlist);
			trace("args = " + args);
			return gottenlist.children()[ positionNumber ];
		}
		
		public function getPositionInList( gottenlist:XML, labelname:XML):int
		{
			var returnint:int = -1;
			
			for( var i:int = 0; i < gottenlist.children().length(); i++)
			{
				if ( gottenlist.children()[i] == labelname )
				{
					return i + 1;
				}
			}
			
			return returnint;
		}	}}